package graphics.raytracing;

import java.util.ArrayList;
import java.util.Collection;

import util.MatrixOperationsF;
import static util.MatrixOperationsF.*;
public class SimpleTriangleMesh implements Model{
	private Collection<Triangle> _content = new ArrayList<>();
	public void add(Triangle t)
	{
		_content.add(t);
	}
	
	@Override
	public CastResult cast(Ray ray) {
		//determine closest
		float dist = Float.MAX_VALUE;
		CastResult rv =null;
		for(Triangle t:_content)
			if(t.intersects(ray))
			{
				CastResult temp=t.cast(ray);
				float d =dist(MatrixOperationsF.add(ray.getOrigin(),negate(temp.getLocation())));
				if(d<dist)
				{
					rv=temp;
					dist =d; 
				}
			}
		
		return rv;
	}

	@Override
	public boolean intersects(Ray ray) {
		return false;
	}

}
